<template>
    <div id="under-net-order" class="order-content">
        <div class="top" style="width: 100%; overflow: auto">
            <el-row class="row-height top-row" style="border-bottom: 1px solid #c9c9c9">
                <el-col :span="8" class="col-box" style="border-right: 1px solid #c9c9c9">
                    <h3 class="title">风控指令:<el-divider></el-divider></h3>
                    <el-form label-width="110px" size="small">
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="外部指令序号:"
                                    ><el-input :value="riskOrderForm.outerOrderCode" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="产品序号:">
                                    <RiskEntryInput @set-entry-data="getEntryslist" :returnDatas="riskOrderForm.fundCode" />
                                    <!-- <el-select v-model="riskOrderForm.fundCode" @change="handleFundCodeChange" filterable size="mini">
                                        <el-option
                                            v-for="i in fundCodeSelectData"
                                            :key="i.fundCode"
                                            :label="i.fundCode + ' ' + i.fundNameSt"
                                            :value="i.fundCode"
                                        >
                                        </el-option>
                                    </el-select> -->
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="组合编码:">
                                    <el-select v-model="riskOrderForm.fundAccountCode" size="mini">
                                        <el-option
                                            v-for="i in computedFundAccountCodeSelectData"
                                            :key="i.fundAccountCode"
                                            :label="i.fundAccountCode + ' ' + i.fundAccountName"
                                            :value="i.fundAccountCode"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="价格模式:">
                                    <el-select v-model="riskOrderForm.orderPriceType" size="mini">
                                        <el-option
                                            v-for="i in investPriceSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="投资类型:">
                                    <el-select v-model="riskOrderForm.investType" size="mini">
                                        <el-option
                                            v-for="i in investTypeSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="指令用途:">
                                    <el-select v-model="riskOrderForm.orderPurpose" size="mini">
                                        <el-option
                                            v-for="i in orderPurposeSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="指令优先级:">
                                    <el-select v-model="riskOrderForm.orderLevel" size="mini">
                                        <el-option
                                            v-for="i in orderLevelSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="证券代码:">
                                    <el-select
                                        v-model="riskOrderForm.stockCode"
                                        @change="handleStockCode"
                                        filterable
                                        remote
                                        :remote-method="searchStockCodeList"
                                        :loading="selectLoading"
                                        style="width: 100%"
                                        size="mini"
                                    >
                                        <el-option
                                            v-for="i in stockCodeSelectData"
                                            :key="i.stockCode"
                                            :label="i.stockCode + ' ' + i.stockNameSt"
                                            :value="i.stockCode"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="订单方向:">
                                    <el-select v-model="riskOrderForm.orderDirection" size="mini" :class="['font-color-' + textColor]">
                                        <el-option
                                            v-for="i in orderDirectionSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="指令价格:">
                                    <RiskInputNumber
                                        :maxlength="15"
                                        :inputAfter="'元'"
                                        :colorStyle="textColor"
                                        :input="riskOrderForm.orderPrice"
                                        @getInputNumber="getOrderBalance(arguments)"
                                        :field="'orderPrice'"
                                        :precision="2"
                                        :min="0"
                                        controls-position="right"
                                        size="mini"
                                    />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="指令数量:">
                                    <RiskInputNumber
                                        :maxlength="15"
                                        :inputAfter="'股'"
                                        :colorStyle="textColor"
                                        :input="riskOrderForm.orderAmount"
                                        @getInputNumber="getOrderBalance(arguments)"
                                        :field="'orderAmount'"
                                        :min="0"
                                        controls-position="right"
                                        size="mini"
                                    />
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="指令金额:">
                                    <el-tooltip
                                        v-if="riskOrderForm.orderBalance && riskOrderForm.orderBalance !== 'NaN'"
                                        placement="top"
                                        :content="computedorderBalanceChinese"
                                    >
                                        <RiskInputNumber
                                            :maxlength="15"
                                            :inputAfter="'元'"
                                            :colorStyle="textColor"
                                            :input="riskOrderForm.orderBalance"
                                            :field="'orderBalance'"
                                            @getInputNumber="getOrderBalance(arguments)"
                                            :precision="2"
                                            :min="0"
                                            controls-position="right"
                                            size="mini"
                                        />
                                    </el-tooltip>
                                    <RiskInputNumber
                                        :maxlength="15"
                                        :inputAfter="'元'"
                                        :colorStyle="textColor"
                                        v-else
                                        :input="riskOrderForm.orderBalance"
                                        :field="'orderBalance'"
                                        @getInputNumber="getOrderBalance(arguments)"
                                        :precision="2"
                                        :min="0"
                                        controls-position="right"
                                        size="mini"
                                    />
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="网下申购金额:">
                                    <RiskInputNumber
                                        :maxlength="15"
                                        :inputAfter="'元'"
                                        :colorStyle="textColor"
                                        :input="riskOrderForm.applyAmount"
                                        :field="'applyAmount'"
                                        @getInputNumber="getOrderBalance(arguments)"
                                        :precision="2"
                                        :min="0"
                                        controls-position="right"
                                        size="mini"
                                    />
                                </el-form-item>
                            </el-col>
                            <el-col :span="12">
                                <el-form-item label="预估中签率:"
                                    ><el-input-number
                                        v-model="riskOrderForm.winningRate"
                                        :precision="4"
                                        :step="0.1"
                                        :min="0"
                                        :max="1"
                                        controls-position="right"
                                        size="mini"
                                    ></el-input-number
                                ></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="12">
                                <el-form-item label="撤单类型:">
                                    <el-select v-model="riskOrderForm.cancelType" size="mini">
                                        <el-option
                                            v-for="i in cancelTypeSelectData"
                                            :key="i.dictKey"
                                            :label="i.dictKey + ' ' + i.dictKeyName"
                                            :value="i.dictKey"
                                        >
                                        </el-option>
                                    </el-select>
                                </el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col>
                                <el-form-item label="备注:"><el-input v-model="riskOrderForm.remark" size="mini"></el-input></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row" style="float: right">
                            <el-select style="width: 150px; margin-right: 10px" v-model="riskOrderForm.directMode" size="mini">
                                <el-option label="从严控制" value="0"></el-option>
                                <el-option label="非从严控制" value="1"></el-option>
                            </el-select>
                            <el-button v-authCode="B_0039" @click="handleRemake" size="mini">重置</el-button>
                            <el-button v-authCode="B_0041" @click="handleSubmit('1')" type="primary" size="mini">试算</el-button>
                            <el-button v-authCode="B_0040" @click="handleSubmit('2')" type="primary" size="mini">下单</el-button>
                        </el-row>
                    </el-form>
                </el-col>
                <el-col :span="16" class="col-box security-box">
                    <h3 class="title">证券信息:<el-divider></el-divider></h3>
                    <el-form label-width="110px" size="small">
                        <el-row class="form-row">
                            <el-col :span="6">
                                <el-form-item label="证券编码:"
                                    ><el-input :value="stockMessageMsg.returnData.stockCode" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="产品对外代码:"
                                    ><el-input :value="stockMessageMsg.returnData.productCode" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="证券全称:"
                                    ><el-input :value="stockMessageMsg.returnData.stockName" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="证券简称:"
                                    ><el-input :value="stockMessageMsg.returnData.stockNameSt" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="6">
                                <el-form-item label="证券发行方式:"
                                    ><el-input :value="stockMessageMsg.returnData.stIsType" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="上市日期:"
                                    ><el-input :value="stockMessageMsg.returnData.listDate" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="上市天数:"
                                    ><el-input :value="stockMessageMsg.returnData.stListDays" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="是否退市:"
                                    ><el-input :value="stockMessageMsg.returnData.stop" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="6">
                                <el-form-item label="流通股本:"
                                    ><el-input :value="stockMessageMsg.returnData.turnoverAmount" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="总股本:"
                                    ><el-input :value="stockMessageMsg.returnData.totalAmount" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="流通市值:"
                                    ><el-input :value="stockMessageMsg.returnData.turnoverValue" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="总市值:"
                                    ><el-input :value="stockMessageMsg.returnData.totalValue" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>
                        <el-row class="form-row">
                            <el-col :span="6">
                                <el-form-item label="证券收盘价:"
                                    ><el-input :value="stockMessageMsg.returnData.marketCode" disabled size="mini">
                                        <template slot="append">元</template></el-input
                                    ></el-form-item
                                >
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="证券类型:"><el-input :value="stockType" disabled size="mini"></el-input></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="币种:"
                                    ><el-input :value="stockMessageMsg.returnData.curCode" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                            <el-col :span="6">
                                <el-form-item label="面值:"
                                    ><el-input :value="stockMessageMsg.returnData.facePrice" disabled size="mini"></el-input
                                ></el-form-item>
                            </el-col>
                        </el-row>
                    </el-form>
                    <h3 class="title" style="margin-top: 6px">持仓信息:<el-divider></el-divider></h3>

                    <!-- <vxe-table
                        :auto-resize="true"
                        resizable
                        ref="xTable"
                        v-tableTop="pages.currentPage"
                        show-header-overflow="tooltip"
                        show-overflow="tooltip"
                        :data="data"
                        border
                        style="width: 100%"
                        size="mini"
                    >
                        <vxe-column
                            v-for="item in positionsListMsg.title"
                            :key="item.name"
                            :width="item.width || ''"
                            :min-width="item.minWidth || ''"
                            :title="item.name"
                            :field="item.prop || ''"
                            :filters="item.filters"
                            :filter-method="filterHandler"
                            :show-overflow-tooltip="true"
                            show-overflow
                        >
                            <template #filter="{ $panel, column }" v-if="item.search">
                                <el-input
                                    type="type"
                                    v-for="(option, index) in column.filters"
                                    :key="index"
                                    v-model="option.data"
                                    @input="$panel.changeOption($event, !!option.data, option)"
                                />
                            </template>
                        </vxe-column>
                    </vxe-table> -->
                    <risk-table :msg="positionsListMsg" @getList="getPositionList"></risk-table>
                </el-col>
            </el-row>
        </div>
        <el-row class="row-height bottom-row">
            <el-col class="col-box">
                <h3 class="title">
                    <el-row>
                        <el-col :span="3">风控结果:<status-tag :code="riskResult"></status-tag></el-col>
                        <el-col :span="5">
                            <span>试算/下单时间: </span>
                            <span style="color: red">{{ calcTime }}</span>
                        </el-col>
                        <el-col :span="5">
                            <span>计算耗时: </span>
                            <span style="color: red">{{ takeTime }}</span>
                        </el-col>
                        <el-col :span="4"
                            >条目检查数:
                            <span v-show="riskResListMsg.returnData.data.length" style="color: red">{{
                                riskResListMsg.returnData.data.length
                            }}</span></el-col
                        >
                    </el-row>
                    <el-divider></el-divider>
                </h3>
                <div>
                    <RiskResult :riskResultTable="riskResultTable" :stockInfoPojo="stockInfoPojo" />
                </div>
            </el-col>
        </el-row>
    </div>
</template>

<script lang="ts">
import { Component, Vue, Watch } from 'vue-property-decorator';
import RiskTable from '@/common/components/risk-table.vue';
import DictionConstUtil, { SGU_CACHE, objToArr } from '@/utils/diction-const-util';
import Invest from '@/common/dict/invest';
import { UUID, NumberToWords, getCurrentPageData, numberFormat, unitShow, highlightColor } from '@/utils/tools';
import StatusTag from './components/status-tag.vue';
import BranchTag from './components/branch-tag.vue';
import RiskResult from './components/risk-result.vue';
import { getUser } from '@/utils/user-util';
import RiskEntryInput from '@/common/components/risk-entry-input.vue';
import RiskInputNumber from '@/pages/risk-measure/components/risk-input-number.vue';
import MeasureColumnUtil from './utils/measure-columns-util';

@Component({
    name: 'UnderNetOrder',
    components: { RiskTable, StatusTag, BranchTag, RiskResult, RiskEntryInput, RiskInputNumber },
})
export default class UnderNetOrder extends Vue {
    stockType: string = '';

    stockTypes: any = {};

    // 风控指令表单
    riskOrderForm = {
        orderType: '', // 下单类型
        marketCode: '', // 市场序号
        reportCode: '', // 申报代码
        orderUser: getUser().userCode, // 下单人
        stockType: '',
        directMode: '0', // 下单模式，默认有序从严
        outerOrderCode: '自动生成', // 外部指令序号
        fundCode: '', // 产品序号
        fundAccountCode: '', // 组合编码
        orderPriceType: '1', // 价格模式
        investType: '1', // 投资类型
        orderPurpose: '1', // 指令用途
        orderLevel: '1', // 指令优先级
        stockCode: '', // 证券代码
        orderDirection: '', // 订单方向
        orderPrice: undefined, // 指令价格
        orderAmount: undefined, // 指令数量
        orderBalance: undefined, // 指令金额
        applyAmount: undefined, // 网下申购金额
        winningRate: '1', // 预估中签率
        cancelType: '3', // 撤单类型
        remark: '', // 备注
        requestId: '', // 请求序号
    };

    Invest: any = new Invest();

    fundCodeSelectData: any[] = []; // 产品序号下拉框数据

    fundAccountCodeSelectData: any[] = []; // 组合编码下拉框数据

    investPriceSelectData: any[] = []; // 价格模式下拉框数据

    investTypeSelectData: any[] = []; // 投资类型下拉框数据

    orderPurposeSelectData: any[] = []; // 指令用途下拉框数据

    orderLevelSelectData: any[] = []; // 指令优先级下拉框数据

    stockCodeSelectData: any[] = []; // 证券代码下拉框数据

    allStockType: any[] = []; // 所有订单方向数据

    allOrderDirection: any[] = [];

    orderDirectionSelectData: any[] = []; // 订单方向下拉框数据

    cancelTypeSelectData: any[] = []; // 撤单类型下拉框数据

    selectLoading: boolean = false; // 下拉框远程搜索时的加载状态

    calcTime: string = ''; // 下单/试算时间

    takeTime: string | number = ''; // 计算耗时

    riskResult: string | number = ''; // 风控结果

    entryType = {}; // 风险类型字典

    compareDirection = {}; // 比较方向字典

    // 风控结果表数据
    riskResultTable: any[] = [];

    tableKey: number = 0;

    // 图标dom
    private iconDom: any = null;

    textColor: string = ''; // 红绿凸显

    // 证券代码下拉框数据相关
    stockCodeMsg = {
        url: '/original/stock/list',
        submit: {
            paging: { total: 0, currentPage: 1, totalPage: 0, pageSize: 20 },
            multStockType: ['a', '1', 'C', '5'],
            multMarketCode: ['1', '2'],
            stockCode: '',
        },
    };

    // 证券信息相关
    stockMessageMsg = { url: '/baseInfomation/underNetPurChase/stock/', returnData: {} };

    // 持仓信息相关
    positionsListMsg = {
        url: '/baseInfomation/stocks/',
        returnData: { data: [], total: 0 },
        dataKey: 'data',
        title: new MeasureColumnUtil().positionColumns,
        height: '150px',
        // 隐藏页码
        hidePage: false,
        checked: { on: false, option: false },
    };

    positionList: any[] = [];

    // 风控结果相关
    riskResListMsg = {
        url: '/dataEngine/order/underPurOrder',
        returnData: { data: [] },
        dataKey: 'data',

        // height: '350px',
        // 隐藏页码
        hidePage: true,
        checked: { on: false, option: false },
    };
    stockInfoPojo: any = {};

    async mounted() {
        // 获取产品信息 (产品序号下拉框数据)
        this.fundCodeSelectData = await SGU_CACHE('FundInfo', '/fundInfo/list', []);
        // 获取组合编码下拉框数据
        let arr = await SGU_CACHE('FundAccount', '/fundInfo/accounts', []);
        arr.forEach(item => {
            this.fundAccountCodeSelectData[item.fundCode] = item.fundAccounts;
        });
        // 获取价格模式下拉框数据
        this.investPriceSelectData = await SGU_CACHE('PriceType', '/dict/list/code/Y_000237', []);
        // 获取投资类型下拉框数据
        this.investTypeSelectData = objToArr(this.Invest.investType);
        // 获取指令用途下拉框数据
        this.orderPurposeSelectData = objToArr(Invest.investPurpose);
        // 获取指令优先级下拉框数据
        this.orderLevelSelectData = objToArr(this.Invest.investLevel);
        // 获取证券代码下拉框数据
        this.getstockCodeList();
        // 获取所有证券类别 (用于筛选订单方向)
        this.allStockType = await SGU_CACHE('StockType', '/dict/stockType/list', []);
        this.stockTypes = DictionConstUtil.ListToPojo(this.allStockType);

        // 获取所有订单方向
        this.allOrderDirection = await SGU_CACHE('TradeDirection', '/dict/tradeDirections', []);
        // 获取撤单类型下拉框数据
        this.cancelTypeSelectData = objToArr(this.Invest.CancelType);
        // 获取风险类型字典
        this.entryType = this.Invest.entryType;
        // 获取比较方向字典
        this.compareDirection = this.Invest.CompareDirection;
        // this.changeTable();
        // this.tableKey++;
    }

    // 组合编码下拉框计算属性
    get computedFundAccountCodeSelectData() {
        return this.fundAccountCodeSelectData[this.riskOrderForm.fundCode] || [];
    }

    // 监听 组合编码计算属性 (每当计算属性变动时 自动选中第一项)
    @Watch('computedFundAccountCodeSelectData', { immediate: true, deep: true })
    watchcomputedFundAccountCode(newData) {
        if (newData && newData.length) {
            this.riskOrderForm.fundAccountCode = newData[0].fundAccountCode;
        }
    }

    /**
     * 判断字段颜色
     */
    @Watch('riskOrderForm', { immediate: true, deep: true })
    handleFieldColor() {
        if (this.riskOrderForm.orderDirection == '1') {
            this.textColor = highlightColor()[1];
        } else if (this.riskOrderForm.orderDirection == '2') {
            this.textColor = highlightColor()[2];
        } else {
            this.textColor = highlightColor()[0];
        }
    }

    // 转表格筛选下拉框数据
    objToArr(param) {
        let list = [];
        for (let key in param) {
            list.push({ value: key, label: param[key] });
        }
        return list;
    }

    filterEntryTypeMethod({ value, row, column }) {
        return row.entryType == value;
    }

    // 表格列筛选数据
    filterHandler({ option, row, column }) {
        const property = column['property'];
        return row[property].includes(option.data);
    }

    // 获取证券代码下拉框数据
    getstockCodeList() {
        this.selectLoading = true;
        this.$axios.post(this.stockCodeMsg.url, this.stockCodeMsg.submit).then((res: any) => {
            this.stockCodeSelectData = res.list || [];
            this.selectLoading = false;
        });
    }

    // 证券代码下拉框远程搜索
    searchStockCodeList(e: string) {
        this.stockCodeMsg.submit.stockCode = e;
        this.getstockCodeList();
    }

    getEntryslist(val: any) {
        if (val) {
            this.riskOrderForm.fundCode = val;
            this.handleFundCodeChange(val);
        }
    }

    // 产品序号选中事件 => 请求持仓信息
    handleFundCodeChange(e: string) {
        this.$axios(this.positionsListMsg.url + e).then((res: any) => {
            if (res.length) {
                this.positionsListMsg.returnData.data = res;
                this.positionsListMsg.returnData.total = res.length;
                this.positionList = res;
            } else {
                this.yh_message_info('没有申购持仓信息');
            }
        });
    }

    // 证券代码选中事件 => 请求 证券信息 & 订单方向
    handleStockCode(e) {
        this.riskOrderForm.orderDirection = '';

        this.$axios(this.stockMessageMsg.url + e).then((res: any) => {
            res.type = '申购';
            res.stop = res.stStop === true ? '是' : '否';
            this.stockMessageMsg.returnData = res;
            this.stockType = this.stockTypes[res.stockType];
        });

        let st = this.stockCodeSelectData.find(item => item.stockCode === e);
        this.stockInfoPojo[e] = st.stockNameSt;

        let stockType = null;
        for (let i = 0; i < this.stockCodeSelectData.length; i++) {
            const ele = this.stockCodeSelectData[i];
            if (ele.stockCode === e) {
                stockType = ele.stockType;
                this.riskOrderForm.marketCode = ele.marketCode;
                this.riskOrderForm.reportCode = ele.reportCode;
                this.riskOrderForm.stockType = ele.stockType;
                break;
            }
        }
        let stockTypeE = this.allStockType.find(item => item.dictKey === stockType);
        if (stockTypeE && stockTypeE.param1) {
            this.orderDirectionSelectData = this.allOrderDirection.filter(item => stockTypeE.param1.includes(item.dictKey) && item.dictKey !== 'l'); // 屏蔽转融通
        }
    }

    getPositionList(pages) {
        this.positionsListMsg.returnData.data = getCurrentPageData(this.positionList, pages.currentPage, pages.pageSize);
    }

    // 获取指令金额 = 指令价格 * 指令数量
    getOrderBalance(args: any) {
        let value = args[0];
        let field = args[1];
        this.riskOrderForm[field] = value;
        if (field === 'orderPrice' || field === 'orderAmount') {
            this.riskOrderForm.orderBalance = (Number(this.riskOrderForm.orderPrice) * Number(this.riskOrderForm.orderAmount)).toString();
        }
    }

    // 指令金额 大写中文
    get computedorderBalanceChinese() {
        return NumberToWords(this.riskOrderForm.orderBalance.toString());
    }

    // 重置按钮事件
    handleRemake() {
        this.riskOrderForm = {
            orderType: '', // 下单类型
            marketCode: '', // 市场序号
            reportCode: '', // 申报代码
            orderUser: getUser().userCode, // 下单人
            stockType: '',
            directMode: '0', // 是否从严， 默认0从严控制
            outerOrderCode: '自动生成', // 外部指令序号
            fundCode: '', // 产品序号
            fundAccountCode: '', // 组合编码
            orderPriceType: '1', // 价格模式
            investType: '1', // 投资类型
            orderPurpose: '1', // 指令用途
            orderLevel: '1', // 指令优先级
            stockCode: '', // 证券代码
            orderDirection: '', // 订单方向
            orderPrice: undefined, // 指令价格
            orderAmount: undefined, // 指令数量
            orderBalance: undefined, // 指令金额
            applyAmount: undefined, // 网下申购金额
            winningRate: '1', // 预估中签率
            cancelType: '3', // 撤单类型
            remark: '', // 备注
            requestId: '', // 请求序号
        };
        this.stockMessageMsg.returnData = {};
        this.positionsListMsg.returnData.data = [];
        this.positionsListMsg.returnData.total = 0;
        this.stockType = '';
    }

    // 校验提交参数
    verifyInstructionParam() {
        let param = this.riskOrderForm;
        if (!param.orderType) {
            this.yh_message_error('下单类型不可为空');
            return false;
        }
        if (!param.outerOrderCode) {
            this.yh_message_error('外部指令序号不可为空');
            return false;
        }
        if (!param.fundCode) {
            this.yh_message_error('产品代码不可为空');
            return false;
        }
        if (!param.fundAccountCode) {
            this.yh_message_error('组合编码不可为空');
            return false;
        }
        if (!param.orderDirection) {
            this.yh_message_error('订单方向不可为空');
            return false;
        }
        if (!param.orderUser) {
            this.yh_message_error('下单人不可为空');
            return false;
        }
        if (!param.investType) {
            this.yh_message_error('投资类型不可为空');
            return false;
        }
        if (!param.stockCode) {
            this.yh_message_error('申报代码不可为空');
            return false;
        }
        if (!param.marketCode) {
            this.yh_message_error('市场序号不可为空');
            return false;
        }
        if (param.orderPrice === undefined) {
            this.yh_message_error('指令价格不可为空');
            return false;
        }
        if (param.orderAmount === undefined) {
            this.yh_message_error('指令数量不可为空');
            return false;
        }
        if (param.orderBalance === undefined) {
            this.yh_message_error('指令金额不可为空');
            return false;
        }
        if (!param.orderLevel) {
            this.yh_message_error('指令优先级不可为空');
            return false;
        }
        if (param.applyAmount === undefined) {
            this.yh_message_error('网下申购金额不可为空');
            return false;
        }
        if (!param.winningRate) {
            this.yh_message_error('预估中签率不可为空');
            return false;
        }
        return true;
    }

    // 提交事件
    handleSubmit(orderType: string) {
        // 下单类型
        this.riskOrderForm.orderType = orderType;
        // 计算耗时
        let start = window.performance.now();
        // 下单号
        this.riskOrderForm.outerOrderCode = 'unp' + UUID() + '-' + new Date().getTime();
        // 请求id
        this.riskOrderForm.requestId = 'runp' + UUID() + '-' + new Date().getTime();

        // 下单人姓名
        // this.riskOrderForm.orderUser = getUser().userName;
        // 校验参数规则
        if (!this.verifyInstructionParam()) {
            return;
        }
        // 获取当前提交时间 (试算/下单时间)
        // 补零
        let fillZero = n => {
            let result = n.toString().length === 1 ? '0' + n : n;
            return result;
        };
        // 时间戳转换 yyyy-MM-dd
        let formatTime = (t = new Date()) => {
            let d = new Date(t);
            let year = d.getFullYear();
            let month = d.getMonth() + 1;
            let date = d.getDate();
            let hours = d.getHours();
            let minutes = d.getMinutes();
            let seconds = d.getSeconds();
            let result = `${year}-${fillZero(month)}-${fillZero(date)} ${fillZero(hours)}:${fillZero(minutes)}:${fillZero(seconds)}`;
            return result;
        };
        this.calcTime = formatTime(new Date());
        // 提交指令 => 获取风控结果
        this.$axios.post(this.riskResListMsg.url, this.riskOrderForm).then((res: any) => {
            this.yh_message_success('指令信息提交成功');
            // 风控结果
            this.riskResult = res.thresholdType;
            // 计算耗时
            let end = window.performance.now();
            this.takeTime = ((end - start) / 1000).toFixed(3) + '秒';

            let data = res.resultList || [];

            // 根据产品代码 匹配产品名称
            data.forEach(ele => {
                ele.requestId = res.requestId;
                // 风险类型
                ele.entryType2 = this.entryType[ele.entryType];
                // 比较方向
                ele.compareType2 = this.compareDirection[ele.compareType];

                for (let i = 0; i < this.fundCodeSelectData.length; i++) {
                    const item = this.fundCodeSelectData[i];
                    if (ele.fundCode === item.fundCode) {
                        ele.fundNameSt = item.fundNameSt;
                    }
                }
            });
            this.$set(this.riskResListMsg.returnData, 'data', data);
            this.riskResultTable = this.riskResListMsg.returnData.data;
        });
    }
}
</script>

<style lang="scss" scoped>
@import './style/measure';

#under-net-order {
    width: 100%;
    height: 100vh;
    min-height: 600px;
    .row-height {
        // height: 50%;
        // min-height: 450px;
        .col-box {
            // height: 100%;
            padding: 10px 5px;
            .el-divider {
                margin: 0;
                margin-top: 5px;
            }
            .form-row {
                margin-top: 3px;
                .el-form-item--small {
                    margin: 0;
                    & /deep/ .el-form-item__label {
                        color: #575757;
                    }
                    & /deep/ .el-input__inner {
                        height: 28px;
                        line-height: 28px;
                    }
                    .font-color-red {
                        /deep/ input {
                            color: red !important;
                        }
                        /deep/ .el-input-group__append {
                            color: red !important;
                        }
                    }
                    .font-color-green {
                        /deep/ input {
                            color: green !important;
                        }
                        /deep/ .el-input-group__append {
                            color: green !important;
                        }
                    }
                }
            }
        }
        .security-box {
            .form-row {
                .el-form-item--small {
                    & /deep/ .el-input__inner {
                        background: #fff;
                        color: #575757;
                    }
                }
            }
        }
        // /deep/.vxe-table {
        //   height: 150px;
        //   min-height: fit-content;
        //   max-height: 350px;
        // }
    }
}
</style>
